home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / info.lzh / INFO / GCC_INFO.5 < prev    next >
Encoding:
GNU Info File  |  1993-10-21  |  50.0 KB  |  1,225 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.54 from the input
  2. file gcc.texi.
  3.  
  4.    This file documents the use and the internals of the GNU compiler.
  5.  
  6.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the sections entitled "GNU General Public License" and "Protect
  15. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  16. original, and provided that the entire resulting derived work is
  17. distributed under the terms of a permission notice identical to this
  18. one.
  19.  
  20.    Permission is granted to copy and distribute translations of this
  21. manual into another language, under the above conditions for modified
  22. versions, except that the sections entitled "GNU General Public
  23. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  24. permission notice, may be included in translations approved by the Free
  25. Software Foundation instead of in the original English.
  26.  
  27. File: gcc.info,  Node: Cross-Compiler,  Next: PA Install,  Prev: Other Dir,  Up: Installation
  28.  
  29. Building and Installing a Cross-Compiler
  30. ========================================
  31.  
  32.    GNU CC can function as a cross-compiler for many machines, but not
  33. all.
  34.  
  35.    * Cross-compilers for the Mips as target do not work because the
  36.      auxiliary programs `mips-tdump.c' and `mips-tfile.c' can't be
  37.      compiled on anything but a Mips.
  38.  
  39.    * Cross-compilers to or from the Vax probably don't work completely
  40.      because the Vax uses an incompatible floating point format (not
  41.      IEEE format).
  42.  
  43.    Since GNU CC generates assembler code, you probably need a
  44. cross-assembler that GNU CC can run, in order to produce object files.
  45. If you want to link on other than the target machine, you need a
  46. cross-linker as well.  You also need header files and libraries suitable
  47. for the target machine that you can install on the host machine.
  48.  
  49.    To build GNU CC as a cross-compiler, you start out by running
  50. `configure'.  You must specify two different configurations, the host
  51. and the target.  Use the `--host=HOST' option for the host and
  52. `--target=TARGET' to specify the target type.  For example, here is how
  53. to configure for a cross-compiler that runs on a hypothetical Intel 386
  54. system and produces code for an HP 68030 system running BSD:
  55.  
  56.      configure --target=m68k-hp-bsd4.3 --host=i386-bozotheclone-bsd4.3
  57.  
  58.    Next you should install the cross-assembler and cross-linker (and
  59. `ar' and `ranlib').  Put them in the directory `/usr/local/TARGET/bin'.
  60. The installation of GNU CC will find them there and copy or link them
  61. to the proper place to find them when you run the cross-compiler later.
  62.  
  63.    If you want to install any additional libraries to use with the
  64. cross-compiler, put them in the directory `/usr/local/TARGET/lib'; all
  65. files in that subdirectory will be installed in the proper place when
  66. you install the cross-compiler.  Likewise, put the header files for the
  67. target machine in `/usr/local/TARGET/include'.
  68.  
  69.    You must now produce a substitute for `libgcc1.a'.  Normally this
  70. file is compiled with the "native compiler" for the target machine;
  71. compiling it with GNU CC does not work.  But compiling it with the host
  72. machine's compiler also doesn't work--that produces a file that would
  73. run on the host, and you need it to run on the target.
  74.  
  75.    We can't give you any automatic way to produce this substitute.  For
  76. some targets, the subroutines in `libgcc1.c' are not actually used.
  77. You need not provide the ones that won't be used.  The ones that most
  78. commonly are used are the multiplication, division and remainder
  79. routines--many RISC machines rely on the library for this.  One way to
  80. make them work is to define the appropriate `perform_...' macros for
  81. the subroutines that you need.  If these definitions do not use the C
  82. arithmetic operators that they are meant to implement, you might be
  83. able to compile them with the cross-compiler you are building.  To do
  84. this, specify `LIBGCC1=libgcc1.a OLDCC=./xgcc' when building the
  85. compiler.
  86.  
  87.    Now you can proceed just as for compiling a single-machine compiler
  88. through the step of building stage 1.  If you have not provided some
  89. sort of `libgcc1.a', then compilation will give up at the point where
  90. it needs that file, printing a suitable error message.  If you do
  91. provide `libgcc1.a', then building the compiler will automatically
  92. compile and link a test program called `cross-test'; if you get errors
  93. in the linking, it means that not all of the necessary routines in
  94. `libgcc1.a' are available.
  95.  
  96.    When you are using a cross-compiler configuration, building stage 1
  97. does not compile all of GNU CC.  This is because one part of building,
  98. the compilation of `libgcc2.c', requires use of the cross-compiler.
  99.  
  100.    However, when you type `make install' to install the bulk of the
  101. cross-compiler, that will also compile `libgcc2.c' and install the
  102. resulting `libgcc.a'.
  103.  
  104.    Do not try to build stage 2 for a cross-compiler.  It doesn't work to
  105. rebuild GNU CC as a cross-compiler using the cross-compiler, because
  106. that would produce a program that runs on the target machine, not on the
  107. host.  For example, if you compile a 386-to-68030 cross-compiler with
  108. itself, the result will not be right either for the 386 (because it was
  109. compiled into 68030 code) or for the 68030 (because it was configured
  110. for a 386 as the host).  If you want to compile GNU CC into 68030 code,
  111. whether you compile it on a 68030 or with a cross-compiler on a 386, you
  112. must specify a 68030 as the host when you configure it.
  113.  
  114. File: gcc.info,  Node: PA Install,  Next: Sun Install,  Prev: Cross-Compiler,  Up: Installation
  115.  
  116. GNU CC on the HP Precision Architecture
  117. =======================================
  118.  
  119.    There are two variants of this CPU, called 1.0 and 1.1, which have
  120. different machine descriptions.  You must use the right one for your
  121. machine.  All 7NN machines and 8N7 machines use 1.1, while all other
  122. 8NN machines use 1.0.
  123.  
  124.    The easiest way to handle this problem is to use `configure hpNNN'
  125. or `configure hpNNN-hpux', where NNN is the model number of the
  126. machine.  Then `configure' will figure out if the machine is a 1.0 or
  127. 1.1.  Use `uname -a' to find out the model number of your machine.
  128.  
  129.    `-g' does not work on HP-UX, since that system uses a peculiar
  130. debugging format which GNU CC does not know about.  There are
  131. preliminary versions of GAS and GDB for the HP-PA which do work with
  132. GNU CC for debugging.  You can get them by anonymous ftp from
  133. `jaguar.cs.utah.edu' `dist' subdirectory.  You would need to install
  134. GAS in the file
  135.  
  136.      /usr/local/lib/gcc-lib/CONFIGURATION/GCCVERSION/as
  137.  
  138. where CONFIGURATION is the configuration name (perhaps `hpNNN-hpux')
  139. and GCCVERSION is the GNU CC version number.  Do this *before* starting
  140. the build process, otherwise you will get errors from the HPUX
  141. assembler while building `libgcc2.a'.  The command
  142.  
  143.      make install-dir
  144.  
  145. will create the necessary directory hierarchy so you can install GAS
  146. before building GCC.
  147.  
  148.    If you obtained GAS before October 6, 1992 it is highly recommended
  149. you get a new one to avoid several bugs which have been discovered
  150. recently.
  151.  
  152.    To enable debugging, configure GNU CC with the `--gas' option before
  153. building.
  154.  
  155.    It has been reported that GNU CC produces invalid assembly code for
  156. 1.1 machines running HP-UX 8.02 when using the HP assembler.  Typically
  157. the errors look like this:
  158.      as: bug.s @line#15 [err#1060]
  159.        Argument 0 or 2 in FARG upper
  160.               - lookahead = ARGW1=FR,RTNVAL=GR
  161.      as: foo.s @line#28 [err#1060]
  162.        Argument 0 or 2 in FARG upper
  163.               - lookahead = ARGW1=FR
  164.  
  165.    You can check the version of HP-UX you are running by executing the
  166. command `uname -r'.   If you are indeed running HP-UX 8.02 on a 1.1
  167. machine and using the HP assembler then configure GCC with
  168. "hp700-hpux8.02".
  169.  
  170. File: gcc.info,  Node: Sun Install,  Next: 3b1 Install,  Prev: PA Install,  Up: Installation
  171.  
  172. Installing GNU CC on the Sun
  173. ============================
  174.  
  175.    Make sure the environment variable `FLOAT_OPTION' is not set when
  176. you compile `libgcc.a'.  If this option were set to `f68881' when
  177. `libgcc.a' is compiled, the resulting code would demand to be linked
  178. with a special startup file and would not link properly without special
  179. pains.
  180.  
  181.    There is a bug in `alloca' in certain versions of the Sun library.
  182. To avoid this bug, install the binaries of GNU CC that were compiled by
  183. GNU CC.  They use `alloca' as a built-in function and never the one in
  184. the library.
  185.  
  186.    Some versions of the Sun compiler crash when compiling GNU CC.  The
  187. problem is a segmentation fault in cpp.  This problem seems to be due to
  188. the bulk of data in the environment variables.  You may be able to avoid
  189. it by using the following command to compile GNU CC with Sun CC:
  190.  
  191.      make CC="TERMCAP=x OBJS=x LIBFUNCS=x STAGESTUFF=x cc"
  192.  
  193. File: gcc.info,  Node: 3b1 Install,  Next: Unos Install,  Prev: Sun Install,  Up: Installation
  194.  
  195. Installing GNU CC on the 3b1
  196. ============================
  197.  
  198.    Installing GNU CC on the 3b1 is difficult if you do not already have
  199. GNU CC running, due to bugs in the installed C compiler.  However, the
  200. following procedure might work.  We are unable to test it.
  201.  
  202.   1. Comment out the `#include "config.h"' line on line 37 of `cccp.c'
  203.      and do `make cpp'.  This makes a preliminary version of GNU cpp.
  204.  
  205.   2. Save the old `/lib/cpp' and copy the preliminary GNU cpp to that
  206.      file name.
  207.  
  208.   3. Undo your change in `cccp.c', or reinstall the original version,
  209.      and do `make cpp' again.
  210.  
  211.   4. Copy this final version of GNU cpp into `/lib/cpp'.
  212.  
  213.   5. Replace every occurrence of `obstack_free' in the file `tree.c'
  214.      with `_obstack_free'.
  215.  
  216.   6. Run `make' to get the first-stage GNU CC.
  217.  
  218.   7. Reinstall the original version of `/lib/cpp'.
  219.  
  220.   8. Now you can compile GNU CC with itself and install it in the normal
  221.      fashion.
  222.  
  223. File: gcc.info,  Node: Unos Install,  Next: VMS Install,  Prev: 3b1 Install,  Up: Installation
  224.  
  225. Installing GNU CC on Unos
  226. =========================
  227.  
  228.    Use `configure unos' for building on Unos.
  229.  
  230.    The Unos assembler is named `casm' instead of `as'.  For some
  231. strange reason linking `/bin/as' to `/bin/casm' changes the behavior,
  232. and does not work.  So, when installing GNU CC, you should install the
  233. following script as `as' in the subdirectory where the passes of GCC
  234. are installed:
  235.  
  236.      #!/bin/sh
  237.      casm $*
  238.  
  239.    The default Unos library is named `libunos.a' instead of `libc.a'.
  240. To allow GNU CC to function, either change all references to `-lc' in
  241. `gcc.c' to `-lunos' or link `/lib/libc.a' to `/lib/libunos.a'.
  242.  
  243.    When compiling GNU CC with the standard compiler, to overcome bugs in
  244. the support of `alloca', do not use `-O' when making stage 2.  Then use
  245. the stage 2 compiler with `-O' to make the stage 3 compiler.  This
  246. compiler will have the same characteristics as the usual stage 2
  247. compiler on other systems.  Use it to make a stage 4 compiler and
  248. compare that with stage 3 to verify proper compilation.
  249.  
  250.    (Perhaps simply defining `ALLOCA' in `x-crds' as described in the
  251. comments there will make the above paragraph superfluous.  Please
  252. inform us of whether this works.)
  253.  
  254.    Unos uses memory segmentation instead of demand paging, so you will
  255. need a lot of memory.  5 Mb is barely enough if no other tasks are
  256. running.  If linking `cc1' fails, try putting the object files into a
  257. library and linking from that library.
  258.  
  259. File: gcc.info,  Node: VMS Install,  Next: WE32K Install,  Prev: Unos Install,  Up: Installation
  260.  
  261. Installing GNU CC on VMS
  262. ========================
  263.  
  264.    The VMS version of GNU CC is distributed in a backup saveset
  265. containing both source code and precompiled binaries.
  266.  
  267.    To install the `gcc' command so you can use the compiler easily, in
  268. the same manner as you use the VMS C compiler, you must install the VMS
  269. CLD file for GNU CC as follows:
  270.  
  271.   1. Define the VMS logical names `GNU_CC' and `GNU_CC_INCLUDE' to
  272.      point to the directories where the GNU CC executables
  273.      (`gcc-cpp.exe', `gcc-cc1.exe', etc.) and the C include files are
  274.      kept respectively.  This should be done with the commands:
  275.  
  276.           $ assign /system /translation=concealed -
  277.             disk:[gcc.] gnu_cc
  278.           $ assign /system /translation=concealed -
  279.             disk:[gcc.include.] gnu_cc_include
  280.  
  281.      with the appropriate disk and directory names.  These commands can
  282.      be placed in your system startup file so they will be executed
  283.      whenever the machine is rebooted.  You may, if you choose, do this
  284.      via the `GCC_INSTALL.COM' script in the `[GCC]' directory.
  285.  
  286.   2. Install the `GCC' command with the command line:
  287.  
  288.           $ set command /table=sys$common:[syslib]dcltables -
  289.             /output=sys$common:[syslib]dcltables gnu_cc:[000000]gcc
  290.           $ install replace sys$common:[syslib]dcltables
  291.  
  292.   3. To install the help file, do the following:
  293.  
  294.           $ library/help sys$library:helplib.hlb gcc.hlp
  295.  
  296.      Now you can invoke the compiler with a command like `gcc /verbose
  297.      file.c', which is equivalent to the command `gcc -v -c file.c' in
  298.      Unix.
  299.  
  300.    If you wish to use GNU C++ you must first install GNU CC, and then
  301. perform the following steps:
  302.  
  303.   1. Define the VMS logical name `GNU_GXX_INCLUDE' to point to the
  304.      directory where the preprocessor will search for the C++ header
  305.      files.  This can be done with the command:
  306.  
  307.           $ assign /system /translation=concealed -
  308.             disk:[gcc.gxx_include.] gnu_gxx_include
  309.  
  310.      with the appropriate disk and directory name.  If you are going to
  311.      be using libg++, this is where the libg++ install procedure will
  312.      install the libg++ header files.
  313.  
  314.   2. Obtain the file `gcc-cc1plus.exe', and place this in the same
  315.      directory that `gcc-cc1.exe' is kept.
  316.  
  317.      The GNU C++ compiler can be invoked with a command like `gcc /plus
  318.      /verbose file.cc', which is equivalent to the command `g++ -v -c
  319.      file.cc' in Unix.
  320.  
  321.    We try to put corresponding binaries and sources on the VMS
  322. distribution tape.  But sometimes the binaries will be from an older
  323. version than the sources, because we don't always have time to update
  324. them.  (Use the `/version' option to determine the version number of
  325. the binaries and compare it with the source file `version.c' to tell
  326. whether this is so.)  In this case, you should use the binaries you get
  327. to recompile the sources.  If you must recompile, here is how:
  328.  
  329.   1. Execute the command procedure `vmsconfig.com' to copy files
  330.      `vax-vms.h', `xm-vax-vms.h', `vax.c' and `vax.md' to files `tm.h',
  331.      `config.h', `aux-output.c', and `md.' respectively, and to create
  332.      files `tconfig.h' and `hconfig.h'.  This procedure also creates
  333.      several linker option files used by `make-cc1.com' and a data file
  334.      used by `make-l2.com'.
  335.  
  336.           $ @vmsconfig.com
  337.  
  338.   2. Setup the logical names and command tables as defined above.  In
  339.      addition, define the VMS logical name `GNU_BISON' to point at the
  340.      to the directories where the Bison executable is kept.  This
  341.      should be done with the command:
  342.  
  343.           $ assign /system /translation=concealed -
  344.             disk:[bison.] gnu_bison
  345.  
  346.      You may, if you choose, use the `INSTALL_BISON.COM' script in the
  347.      `[BISON]' directory.
  348.  
  349.   3. Install the `BISON' command with the command line:
  350.  
  351.           $ set command /table=sys$common:[syslib]dcltables -
  352.             /output=sys$common:[syslib]dcltables -
  353.             gnu_bison:[000000]bison
  354.           $ install replace sys$common:[syslib]dcltables
  355.  
  356.   4. Type `@make-gcc' to recompile everything (alternatively, you may
  357.      submit the file `make-gcc.com' to a batch queue).  If you wish to
  358.      build the GNU C++ compiler as well as the GNU CC compiler, you must
  359.      first edit `make-gcc.com' and follow the instructions that appear
  360.      in the comments.
  361.  
  362.   5. In order to use GCC, you need a library of functions which GCC
  363.      compiled code will call to perform certain tasks, and these
  364.      functions are defined in the file `libgcc2.c'.  To compile this
  365.      you should use the command procedure `make-l2.com', which will
  366.      generate the library `libgcc2.olb'.  `libgcc2.olb' should be built
  367.      using the compiler built from the same distribution that
  368.      `libgcc2.c' came from, and `make-gcc.com' will automatically do
  369.      all of this for you.
  370.  
  371.      To install the library, use the following commands:
  372.  
  373.           $ library gnu_cc:[000000]gcclib/delete=(new,eprintf)
  374.           $ library libgcc2/extract=*/output=libgcc2.obj
  375.           $ library gnu_cc:[000000]gcclib libgcc2.obj
  376.  
  377.      The first command simply removes old modules that will be replaced
  378.      with modules from libgcc2.  If the VMS librarian complains about
  379.      those modules not being present, simply ignore the message and
  380.      continue on with the next command.
  381.  
  382.      Whenever you update the compiler on your system, you should also
  383.      update the library with the above procedure.
  384.  
  385.   6. You may wish to build GCC in such a way that no files are written
  386.      to the directory where the source files reside.  An example would
  387.      be the when the source files are on a read-only disk.  In these
  388.      cases, execute the following DCL commands (substituting your
  389.      actual path names):
  390.  
  391.           $ assign dua0:[gcc.build_dir.]/translation=concealed, -
  392.                    dua1:[gcc.source_dir.]/translation=concealed  gcc_build
  393.           $ set default gcc_build:[000000]
  394.  
  395.      where `dua1:[gcc.source_dir]' contains the source code, and
  396.      `dua0:[gcc.build_dir]' is meant to contain all of the generated
  397.      object files and executables.  Once you have done this, you can
  398.      proceed building GCC as described above.  (Keep in mind that
  399.      `gcc_build' is a rooted logical name, and thus the device names in
  400.      each element of the search list must be an actual physical device
  401.      name rather than another rooted logical name).
  402.  
  403.   7. *If you are building GNU CC with a previous version of GNU CC, you
  404.      also should check to see that you have the newest version of the
  405.      assembler*.  In particular, GNU CC version 2 treats global constant
  406.      variables slightly differently from GNU CC version 1, and GAS
  407.      version 1.38.1 does not have the patches required to work with GCC
  408.      version 2.  If you use GAS 1.38.1, then `extern const' variables
  409.      will not have the read-only bit set, and the linker will generate
  410.      warning messages about mismatched psect attributes for these
  411.      variables.  These warning messages are merely a nuisance, and can
  412.      safely be ignored.
  413.  
  414.      If you are compiling with a version of GNU CC older than 1.33,
  415.      specify `/DEFINE=("inline=")' as an option in all the
  416.      compilations.  This requires editing all the `gcc' commands in
  417.      `make-cc1.com'.  (The older versions had problems supporting
  418.      `inline'.)  Once you have a working 1.33 or newer GNU CC, you can
  419.      change this file back.
  420.  
  421.   8. If you want to build GNU CC with the VAX C compiler, you will need
  422.      to make minor changes in `make-cccp.com' and `make-cc1.com' to
  423.      choose alternate definitions of `CC', `CFLAGS', and `LIBS'.  See
  424.      comments in those files.  However, you must also have a working
  425.      version of the GNU assembler (GNU as, aka GAS) as it is used as
  426.      the back-end for GNU CC to produce binary object modules and is
  427.      not included in the GNU CC sources.  GAS is also needed to compile
  428.      `libgcc2' in order to build `gcclib' (see above); `make-l2.com'
  429.      expects to be able to find it operational in
  430.      `gnu_cc:[000000]gnu-as.exe'.
  431.  
  432.      To use GNU CC on VMS, you need the VMS driver programs `gcc.exe',
  433.      `gcc.com', and `gcc.cld'.  They are distributed with the VMS
  434.      binaries (`gcc-vms') rather than the GNU CC sources.  GAS is also
  435.      included in `gcc-vms', as is Bison.
  436.  
  437.      Once you have successfully built GNU CC with VAX C, you should use
  438.      the resulting compiler to rebuild itself.  Before doing this, be
  439.      sure to restore the `CC', `CFLAGS', and `LIBS' definitions in
  440.      `make-cccp.com' and `make-cc1.com'.  The second generation
  441.      compiler will be able to take advantage of many optimizations that
  442.      must be suppressed when building with other compilers.
  443.  
  444.    Under previous versions of GNU CC, the generated code would
  445. occasionally give strange results when linked with the sharable
  446. `VAXCRTL' library.  Now this should work.
  447.  
  448.    Even with this version, however, GNU CC itself should not be linked
  449. with the sharable `VAXCRTL'.  The version of `qsort' in `VAXCRTL' has a
  450. bug (known to be present in VMS versions V4.6 through V5.5) which
  451. causes the compiler to fail.
  452.  
  453.    The executables are generated by `make-cc1.com' and `make-cccp.com'
  454. use the object library version of `VAXCRTL' in order to make use of the
  455. `qsort' routine in `gcclib.olb'.  If you wish to link the compiler
  456. executables with the shareable image version of `VAXCRTL', you should
  457. edit the file `tm.h' (created by `vmsconfig.com') to define the macro
  458. `QSORT_WORKAROUND'.
  459.  
  460.    `QSORT_WORKAROUND' is always defined when GNU CC is compiled with
  461. VAX C, to avoid a problem in case `gcclib.olb' is not yet available.
  462.  
  463. File: gcc.info,  Node: WE32K Install,  Next: MIPS Install,  Prev: VMS Install,  Up: Installation
  464.  
  465. Installing GNU CC on the WE32K
  466. ==============================
  467.  
  468.    These computers are also known as the 3b2, 3b5, 3b20 and other
  469. similar names.  (However, the 3b1 is actually a 68000; see *Note 3b1
  470. Install::.)
  471.  
  472.    Don't use `-g' when compiling with the system's compiler.  The
  473. system's linker seems to be unable to handle such a large program with
  474. debugging information.
  475.  
  476.    The system's compiler runs out of capacity when compiling `stmt.c'
  477. in GNU CC.  You can work around this by building `cpp' in GNU CC first,
  478. then use that instead of the system's preprocessor with the system's C
  479. compiler to compile `stmt.c'.  Here is how:
  480.  
  481.      mv /lib/cpp /lib/cpp.att
  482.      cp cpp /lib/cpp.gnu
  483.      echo "/lib/cpp.gnu -traditional $*" > /lib/cpp
  484.      chmod +x /lib/cpp
  485.  
  486.    The system's compiler produces bad code for some of the GNU CC
  487. optimization files.  So you must build the stage 2 compiler without
  488. optimization.  Then build a stage 3 compiler with optimization.  That
  489. executable should work.  Here are the necessary commands:
  490.  
  491.      make LANGUAGES=c CC=stage1/xgcc CFLAGS="-Bstage1/ -g"
  492.      make stage2
  493.      make CC=stage2/xgcc CFLAGS="-Bstage2/ -g -O"
  494.  
  495.    You may need to raise the ULIMIT setting to build a C++ compiler, as
  496. the file `cc1plus' is larger than one megabyte.
  497.  
  498. File: gcc.info,  Node: MIPS Install,  Prev: WE32K Install,  Up: Installation
  499.  
  500. Installing GNU CC on the MIPS
  501. =============================
  502.  
  503.    See *Note Installation:: about whether to use either of the options
  504. `--with-stabs' or `--with-gnu-as'.
  505.  
  506.    The MIPS C compiler needs to be told to increase its table size for
  507. switch statements with the `-Wf,-XNg1500' option in order to compile
  508. `cp-parse.c'.  If you use the `-O2' optimization option, you also need
  509. to use `-Olimit 3000'.  Both of these options are automatically
  510. generated in the `Makefile' that the shell script `configure' builds.
  511. If you override the `CC' make variable and use the MIPS compilers, you
  512. may need to add `-Wf,-XNg1500 -Olimit 3000'.
  513.  
  514.    MIPS computers running RISC-OS can support four different
  515. personalities: default, BSD 4.3, System V.3, and System V.4 (older
  516. versions of RISC-OS don't support V.4).  To configure GCC for these
  517. platforms use the following configurations:
  518.  
  519. `mips-mips-riscos`rev''
  520.      Default configuration for RISC-OS, revision `rev'.
  521.  
  522. `mips-mips-riscos`rev'bsd'
  523.      BSD 4.3 configuration for RISC-OS, revision `rev'.
  524.  
  525. `mips-mips-riscos`rev'sysv4'
  526.      System V.4 configuration for RISC-OS, revision `rev'.
  527.  
  528. `mips-mips-riscos`rev'sysv'
  529.      System V.3 configuration for RISC-OS, revision `rev'.
  530.  
  531.    The revision `rev' mentioned above is the revision of RISC-OS to
  532. use.  You must reconfigure GCC when going from a RISC-OS revision 4 to
  533. RISC-OS revision 5.  This has the effect of avoiding a linker bug (see
  534. *Note Installation Problems:: for more details).
  535.  
  536.    DECstations can support three different personalities: Ultrix, DEC
  537. OSF/1, and OSF/rose.  To configure GCC for these platforms use the
  538. following configurations:
  539.  
  540. `decstation-ultrix'
  541.      Ultrix configuration.
  542.  
  543. `decstation-osf1'
  544.      Dec's version of OSF/1.
  545.  
  546. `decstation-osfrose'
  547.      Open Software Foundation reference port of OSF/1 which uses the
  548.      OSF/rose object file format instead of ECOFF.  Normally, you would
  549.      not select this configuration.
  550.  
  551. File: gcc.info,  Node: C Extensions,  Next: C++ Extensions,  Prev: Installation,  Up: Top
  552.  
  553. Extensions to the C Language Family
  554. ***********************************
  555.  
  556.    GNU C provides several language features not found in ANSI standard
  557. C.  (The `-pedantic' option directs GNU CC to print a warning message if
  558. any of these features is used.)  To test for the availability of these
  559. features in conditional compilation, check for a predefined macro
  560. `__GNUC__', which is always defined under GNU CC.
  561.  
  562.    These extensions are available in C and in the languages derived from
  563. it, C++ and Objective C.  *Note Extensions to the C++ Language: C++
  564. Extensions, for extensions that apply *only* to C++.
  565.  
  566. * Menu:
  567.  
  568. * Statement Exprs::     Putting statements and declarations inside expressions.
  569. * Local Labels::        Labels local to a statement-expression.
  570. * Labels as Values::    Getting pointers to labels, and computed gotos.
  571. * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
  572. * Constructing Calls::    Dispatching a call to another function.
  573. * Naming Types::        Giving a name to the type of some expression.
  574. * Typeof::              `typeof': referring to the type of an expression.
  575. * Lvalues::             Using `?:', `,' and casts in lvalues.
  576. * Conditionals::        Omitting the middle operand of a `?:' expression.
  577. * Long Long::        Double-word integers--`long long int'.
  578. * Zero Length::         Zero-length arrays.
  579. * Variable Length::     Arrays whose length is computed at run time.
  580. * Macro Varargs::    Macros with variable number of arguments.
  581. * Subscripting::        Any array can be subscripted, even if not an lvalue.
  582. * Pointer Arith::       Arithmetic on `void'-pointers and function pointers.
  583. * Initializers::        Non-constant initializers.
  584. * Constructors::        Constructor expressions give structures, unions
  585.                          or arrays as values.
  586. * Labeled Elements::    Labeling elements of initializers.
  587. * Cast to Union::       Casting to union type from any member of the union.
  588. * Case Ranges::        `case 1 ... 9' and such.
  589. * Function Attributes:: Declaring that functions have no side effects,
  590.                          or that they can never return.
  591. * Function Prototypes:: Prototype declarations and old-style definitions.
  592. * Dollar Signs::        Dollar sign is allowed in identifiers.
  593. * Character Escapes::   `\e' stands for the character ESC.
  594. * Variable Attributes::    Specifying attributes of variables.
  595. * Alignment::           Inquiring about the alignment of a type or variable.
  596. * Inline::              Defining inline functions (as fast as macros).
  597. * Extended Asm::        Assembler instructions with C expressions as operands.
  598.                          (With them you can define "built-in" functions.)
  599. * Asm Labels::          Specifying the assembler name to use for a C symbol.
  600. * Explicit Reg Vars::   Defining variables residing in specified registers.
  601. * Alternate Keywords::  `__const__', `__asm__', etc., for header files.
  602. * Incomplete Enums::    `enum foo;', with details to follow.
  603. * Function Names::    Printable strings which are the name of the current
  604.              function.
  605.  
  606. File: gcc.info,  Node: Statement Exprs,  Next: Local Labels,  Up: C Extensions
  607.  
  608. Statements and Declarations in Expressions
  609. ==========================================
  610.  
  611.    A compound statement enclosed in parentheses may appear as an
  612. expression in GNU C.  This allows you to use loops, switches, and local
  613. variables within an expression.
  614.  
  615.    Recall that a compound statement is a sequence of statements
  616. surrounded by braces; in this construct, parentheses go around the
  617. braces.  For example:
  618.  
  619.      ({ int y = foo (); int z;
  620.         if (y > 0) z = y;
  621.         else z = - y;
  622.         z; })
  623.  
  624. is a valid (though slightly more complex than necessary) expression for
  625. the absolute value of `foo ()'.
  626.  
  627.    The last thing in the compound statement should be an expression
  628. followed by a semicolon; the value of this subexpression serves as the
  629. value of the entire construct.  (If you use some other kind of statement
  630. last within the braces, the construct has type `void', and thus
  631. effectively no value.)
  632.  
  633.    This feature is especially useful in making macro definitions "safe"
  634. (so that they evaluate each operand exactly once).  For example, the
  635. "maximum" function is commonly defined as a macro in standard C as
  636. follows:
  637.  
  638.      #define max(a,b) ((a) > (b) ? (a) : (b))
  639.  
  640. But this definition computes either A or B twice, with bad results if
  641. the operand has side effects.  In GNU C, if you know the type of the
  642. operands (here let's assume `int'), you can define the macro safely as
  643. follows:
  644.  
  645.      #define maxint(a,b) \
  646.        ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
  647.  
  648.    Embedded statements are not allowed in constant expressions, such as
  649. the value of an enumeration constant, the width of a bit field, or the
  650. initial value of a static variable.
  651.  
  652.    If you don't know the type of the operand, you can still do this,
  653. but you must use `typeof' (*note Typeof::.) or type naming (*note
  654. Naming Types::.).
  655.  
  656. File: gcc.info,  Node: Local Labels,  Next: Labels as Values,  Prev: Statement Exprs,  Up: C Extensions
  657.  
  658. Locally Declared Labels
  659. =======================
  660.  
  661.    Each statement expression is a scope in which "local labels" can be
  662. declared.  A local label is simply an identifier; you can jump to it
  663. with an ordinary `goto' statement, but only from within the statement
  664. expression it belongs to.
  665.  
  666.    A local label declaration looks like this:
  667.  
  668.      __label__ LABEL;
  669.  
  670. or
  671.  
  672.      __label__ LABEL1, LABEL2, ...;
  673.  
  674.    Local label declarations must come at the beginning of the statement
  675. expression, right after the `({', before any ordinary declarations.
  676.  
  677.    The label declaration defines the label *name*, but does not define
  678. the label itself.  You must do this in the usual way, with `LABEL:',
  679. within the statements of the statement expression.
  680.  
  681.    The local label feature is useful because statement expressions are
  682. often used in macros.  If the macro contains nested loops, a `goto' can
  683. be useful for breaking out of them.  However, an ordinary label whose
  684. scope is the whole function cannot be used: if the macro can be
  685. expanded several times in one function, the label will be multiply
  686. defined in that function.  A local label avoids this problem.  For
  687. example:
  688.  
  689.      #define SEARCH(array, target)                     \
  690.      ({                                               \
  691.        __label__ found;                                \
  692.        typeof (target) _SEARCH_target = (target);      \
  693.        typeof (*(array)) *_SEARCH_array = (array);     \
  694.        int i, j;                                       \
  695.        int value;                                      \
  696.        for (i = 0; i < max; i++)                       \
  697.          for (j = 0; j < max; j++)                     \
  698.            if (_SEARCH_array[i][j] == _SEARCH_target)  \
  699.              { value = i; goto found; }              \
  700.        value = -1;                                     \
  701.       found:                                           \
  702.        value;                                          \
  703.      })
  704.  
  705. File: gcc.info,  Node: Labels as Values,  Next: Nested Functions,  Prev: Local Labels,  Up: C Extensions
  706.  
  707. Labels as Values
  708. ================
  709.  
  710.    You can get the address of a label defined in the current function
  711. (or a containing function) with the unary operator `&&'.  The value has
  712. type `void *'.  This value is a constant and can be used wherever a
  713. constant of that type is valid.  For example:
  714.  
  715.      void *ptr;
  716.      ...
  717.      ptr = &&foo;
  718.  
  719.    To use these values, you need to be able to jump to one.  This is
  720. done with the computed goto statement(1), `goto *EXP;'.  For example,
  721.  
  722.      goto *ptr;
  723.  
  724. Any expression of type `void *' is allowed.
  725.  
  726.    One way of using these constants is in initializing a static array
  727. that will serve as a jump table:
  728.  
  729.      static void *array[] = { &&foo, &&bar, &&hack };
  730.  
  731.    Then you can select a label with indexing, like this:
  732.  
  733.      goto *array[i];
  734.  
  735. Note that this does not check whether the subscript is in bounds--array
  736. indexing in C never does that.
  737.  
  738.    Such an array of label values serves a purpose much like that of the
  739. `switch' statement.  The `switch' statement is cleaner, so use that
  740. rather than an array unless the problem does not fit a `switch'
  741. statement very well.
  742.  
  743.    Another use of label values is in an interpreter for threaded code.
  744. The labels within the interpreter function can be stored in the
  745. threaded code for super-fast dispatching.
  746.  
  747.    You can use this mechanism to jump to code in a different function.
  748. If you do that, totally unpredictable things will happen.  The best way
  749. to avoid this is to store the label address only in automatic variables
  750. and never pass it as an argument.
  751.  
  752.    ---------- Footnotes ----------
  753.  
  754.    (1)  The analogous feature in Fortran is called an assigned goto,
  755. but that name seems inappropriate in C, where one can do more than
  756. simply store label addresses in label variables.
  757.  
  758. File: gcc.info,  Node: Nested Functions,  Next: Constructing Calls,  Prev: Labels as Values,  Up: C Extensions
  759.  
  760. Nested Functions
  761. ================
  762.  
  763.    A "nested function" is a function defined inside another function.
  764. (Nested functions are not supported for GNU C++.)  The nested function's
  765. name is local to the block where it is defined.  For example, here we
  766. define a nested function named `square', and call it twice:
  767.  
  768.      foo (double a, double b)
  769.      {
  770.        double square (double z) { return z * z; }
  771.      
  772.        return square (a) + square (b);
  773.      }
  774.  
  775.    The nested function can access all the variables of the containing
  776. function that are visible at the point of its definition.  This is
  777. called "lexical scoping".  For example, here we show a nested function
  778. which uses an inherited variable named `offset':
  779.  
  780.      bar (int *array, int offset, int size)
  781.      {
  782.        int access (int *array, int index)
  783.          { return array[index + offset]; }
  784.        int i;
  785.        ...
  786.        for (i = 0; i < size; i++)
  787.          ... access (array, i) ...
  788.      }
  789.  
  790.    Nested function definitions must appear in the same part of a
  791. function as variable definitions; that is, before the first line of
  792. code in the enclosing function.
  793.  
  794.    It is possible to call the nested function from outside the scope of
  795. its name by storing its address or passing the address to another
  796. function:
  797.  
  798.      hack (int *array, int size)
  799.      {
  800.        void store (int index, int value)
  801.          { array[index] = value; }
  802.      
  803.        intermediate (store, size);
  804.      }
  805.  
  806.    Here, the function `intermediate' receives the address of `store' as
  807. an argument.  If `intermediate' calls `store', the arguments given to
  808. `store' are used to store into `array'.  But this technique works only
  809. so long as the containing function (`hack', in this example) does not
  810. exit.  If you try to call the nested function through its address after
  811. the containing function has exited, all hell will break loose.
  812.  
  813.    GNU CC implements taking the address of a nested function using a
  814. technique called "trampolines".  A paper describing them is available
  815. from `maya.idiap.ch' in the file `pub/tmb/usenix88-lexic.ps.Z'.
  816.  
  817.    A nested function can jump to a label inherited from a containing
  818. function, provided the label was explicitly declared in the containing
  819. function (*note Local Labels::.).  Such a jump returns instantly to the
  820. containing function, exiting the nested function which did the `goto'
  821. and any intermediate functions as well.  Here is an example:
  822.  
  823.      bar (int *array, int offset, int size)
  824.      {
  825.        __label__ failure;
  826.        int access (int *array, int index)
  827.          {
  828.            if (index > size)
  829.              goto failure;
  830.            return array[index + offset];
  831.          }
  832.        int i;
  833.        ...
  834.        for (i = 0; i < size; i++)
  835.          ... access (array, i) ...
  836.        ...
  837.        return 0;
  838.      
  839.       /* Control comes here from `access'
  840.          if it detects an error.  */
  841.       failure:
  842.        return -1;
  843.      }
  844.  
  845.    A nested function always has internal linkage.  Declaring one with
  846. `extern' is erroneous.  If you need to declare the nested function
  847. before its definition, use `auto' (which is otherwise meaningless for
  848. function declarations).
  849.  
  850.      bar (int *array, int offset, int size)
  851.      {
  852.        __label__ failure;
  853.        auto int access (int *, int);
  854.        ...
  855.        int access (int *array, int index)
  856.          {
  857.            if (index > size)
  858.              goto failure;
  859.            return array[index + offset];
  860.          }
  861.        ...
  862.      }
  863.  
  864. File: gcc.info,  Node: Constructing Calls,  Next: Naming Types,  Prev: Nested Functions,  Up: C Extensions
  865.  
  866. Constructing Function Calls
  867. ===========================
  868.  
  869.    Using the built-in functions described below, you can record the
  870. arguments a function received, and call another function with the same
  871. arguments, without knowing the number or types of the arguments.
  872.  
  873.    You can also record the return value of that function call, and
  874. later return that value, without knowing what data type the function
  875. tried to return (as long as your caller expects that data type).
  876.  
  877. `__builtin_apply_args ()'
  878.      This built-in function returns a pointer of type `void *' to data
  879.      describing how to perform a call with the same arguments as were
  880.      passed to the current function.
  881.  
  882.      The function saves the arg pointer register, structure value
  883.      address, and all registers that might be used to pass arguments to
  884.      a function into a block of memory allocated on the stack.  Then it
  885.      returns the address of that block.
  886.  
  887. `__builtin_apply (FUNCTION, ARGUMENTS, SIZE)'
  888.      This built-in function invokes FUNCTION (type `void (*)()') with a
  889.      copy of the parameters described by ARGUMENTS (type `void *') and
  890.      SIZE (type `int').
  891.  
  892.      The value of ARGUMENTS should be the value returned by
  893.      `__builtin_apply_args'.  The argument SIZE specifies the size of
  894.      the stack argument data, in bytes.
  895.  
  896.      This function returns a pointer of type `void *' to data describing
  897.      how to return whatever value was returned by FUNCTION.  The data
  898.      is saved in a block of memory allocated on the stack.
  899.  
  900.      It is not always simple to compute the proper value for SIZE.  The
  901.      value is used by `__builtin_apply' to compute the amount of data
  902.      that should be pushed on the stack and copied from the incoming
  903.      argument area.
  904.  
  905. `__builtin_return (RESULT)'
  906.      This built-in function returns the value described by RESULT from
  907.      the containing function.  You should specify, for RESULT, a value
  908.      returned by `__builtin_apply'.
  909.  
  910. File: gcc.info,  Node: Naming Types,  Next: Typeof,  Prev: Constructing Calls,  Up: C Extensions
  911.  
  912. Naming an Expression's Type
  913. ===========================
  914.  
  915.    You can give a name to the type of an expression using a `typedef'
  916. declaration with an initializer.  Here is how to define NAME as a type
  917. name for the type of EXP:
  918.  
  919.      typedef NAME = EXP;
  920.  
  921.    This is useful in conjunction with the statements-within-expressions
  922. feature.  Here is how the two together can be used to define a safe
  923. "maximum" macro that operates on any arithmetic type:
  924.  
  925.      #define max(a,b) \
  926.        ({typedef _ta = (a), _tb = (b);  \
  927.          _ta _a = (a); _tb _b = (b);     \
  928.          _a > _b ? _a : _b; })
  929.  
  930.    The reason for using names that start with underscores for the local
  931. variables is to avoid conflicts with variable names that occur within
  932. the expressions that are substituted for `a' and `b'.  Eventually we
  933. hope to design a new form of declaration syntax that allows you to
  934. declare variables whose scopes start only after their initializers;
  935. this will be a more reliable way to prevent such conflicts.
  936.  
  937. File: gcc.info,  Node: Typeof,  Next: Lvalues,  Prev: Naming Types,  Up: C Extensions
  938.  
  939. Referring to a Type with `typeof'
  940. =================================
  941.  
  942.    Another way to refer to the type of an expression is with `typeof'.
  943. The syntax of using of this keyword looks like `sizeof', but the
  944. construct acts semantically like a type name defined with `typedef'.
  945.  
  946.    There are two ways of writing the argument to `typeof': with an
  947. expression or with a type.  Here is an example with an expression:
  948.  
  949.      typeof (x[0](1))
  950.  
  951. This assumes that `x' is an array of functions; the type described is
  952. that of the values of the functions.
  953.  
  954.    Here is an example with a typename as the argument:
  955.  
  956.      typeof (int *)
  957.  
  958. Here the type described is that of pointers to `int'.
  959.  
  960.    If you are writing a header file that must work when included in
  961. ANSI C programs, write `__typeof__' instead of `typeof'.  *Note
  962. Alternate Keywords::.
  963.  
  964.    A `typeof'-construct can be used anywhere a typedef name could be
  965. used.  For example, you can use it in a declaration, in a cast, or
  966. inside of `sizeof' or `typeof'.
  967.  
  968.    * This declares `y' with the type of what `x' points to.
  969.  
  970.           typeof (*x) y;
  971.  
  972.    * This declares `y' as an array of such values.
  973.  
  974.           typeof (*x) y[4];
  975.  
  976.    * This declares `y' as an array of pointers to characters:
  977.  
  978.           typeof (typeof (char *)[4]) y;
  979.  
  980.      It is equivalent to the following traditional C declaration:
  981.  
  982.           char *y[4];
  983.  
  984.      To see the meaning of the declaration using `typeof', and why it
  985.      might be a useful way to write, let's rewrite it with these macros:
  986.  
  987.           #define pointer(T)  typeof(T *)
  988.           #define array(T, N) typeof(T [N])
  989.  
  990.      Now the declaration can be rewritten this way:
  991.  
  992.           array (pointer (char), 4) y;
  993.  
  994.      Thus, `array (pointer (char), 4)' is the type of arrays of 4
  995.      pointers to `char'.
  996.  
  997. File: gcc.info,  Node: Lvalues,  Next: Conditionals,  Prev: Typeof,  Up: C Extensions
  998.  
  999. Generalized Lvalues
  1000. ===================
  1001.  
  1002.    Compound expressions, conditional expressions and casts are allowed
  1003. as lvalues provided their operands are lvalues.  This means that you
  1004. can take their addresses or store values into them.
  1005.  
  1006.    For example, a compound expression can be assigned, provided the last
  1007. expression in the sequence is an lvalue.  These two expressions are
  1008. equivalent:
  1009.  
  1010.      (a, b) += 5
  1011.      a, (b += 5)
  1012.  
  1013.    Similarly, the address of the compound expression can be taken.
  1014. These two expressions are equivalent:
  1015.  
  1016.      &(a, b)
  1017.      a, &b
  1018.  
  1019.    A conditional expression is a valid lvalue if its type is not void
  1020. and the true and false branches are both valid lvalues.  For example,
  1021. these two expressions are equivalent:
  1022.  
  1023.      (a ? b : c) = 5
  1024.      (a ? b = 5 : (c = 5))
  1025.  
  1026.    A cast is a valid lvalue if its operand is an lvalue.  A simple
  1027. assignment whose left-hand side is a cast works by converting the
  1028. right-hand side first to the specified type, then to the type of the
  1029. inner left-hand side expression.  After this is stored, the value is
  1030. converted back to the specified type to become the value of the
  1031. assignment.  Thus, if `a' has type `char *', the following two
  1032. expressions are equivalent:
  1033.  
  1034.      (int)a = 5
  1035.      (int)(a = (char *)(int)5)
  1036.  
  1037.    An assignment-with-arithmetic operation such as `+=' applied to a
  1038. cast performs the arithmetic using the type resulting from the cast,
  1039. and then continues as in the previous case.  Therefore, these two
  1040. expressions are equivalent:
  1041.  
  1042.      (int)a += 5
  1043.      (int)(a = (char *)(int) ((int)a + 5))
  1044.  
  1045.    You cannot take the address of an lvalue cast, because the use of its
  1046. address would not work out coherently.  Suppose that `&(int)f' were
  1047. permitted, where `f' has type `float'.  Then the following statement
  1048. would try to store an integer bit-pattern where a floating point number
  1049. belongs:
  1050.  
  1051.      *&(int)f = 1;
  1052.  
  1053.    This is quite different from what `(int)f = 1' would do--that would
  1054. convert 1 to floating point and store it.  Rather than cause this
  1055. inconsistency, we think it is better to prohibit use of `&' on a cast.
  1056.  
  1057.    If you really do want an `int *' pointer with the address of `f',
  1058. you can simply write `(int *)&f'.
  1059.  
  1060. File: gcc.info,  Node: Conditionals,  Next: Long Long,  Prev: Lvalues,  Up: C Extensions
  1061.  
  1062. Conditionals with Omitted Operands
  1063. ==================================
  1064.  
  1065.    The middle operand in a conditional expression may be omitted.  Then
  1066. if the first operand is nonzero, its value is the value of the
  1067. conditional expression.
  1068.  
  1069.    Therefore, the expression
  1070.  
  1071.      x ? : y
  1072.  
  1073. has the value of `x' if that is nonzero; otherwise, the value of `y'.
  1074.  
  1075.    This example is perfectly equivalent to
  1076.  
  1077.      x ? x : y
  1078.  
  1079. In this simple case, the ability to omit the middle operand is not
  1080. especially useful.  When it becomes useful is when the first operand
  1081. does, or may (if it is a macro argument), contain a side effect.  Then
  1082. repeating the operand in the middle would perform the side effect
  1083. twice.  Omitting the middle operand uses the value already computed
  1084. without the undesirable effects of recomputing it.
  1085.  
  1086. File: gcc.info,  Node: Long Long,  Next: Zero Length,  Prev: Conditionals,  Up: C Extensions
  1087.  
  1088. Double-Word Integers
  1089. ====================
  1090.  
  1091.    GNU C supports data types for integers that are twice as long as
  1092. `long int'.  Simply write `long long int' for a signed integer, or
  1093. `unsigned long long int' for an unsigned integer.  To make an integer
  1094. constant of type `long long int', add the suffix `LL' to the integer.
  1095. To make an integer constant of type `unsigned long long int', add the
  1096. suffix `ULL' to the integer.
  1097.  
  1098.    You can use these types in arithmetic like any other integer types.
  1099. Addition, subtraction, and bitwise boolean operations on these types
  1100. are open-coded on all types of machines.  Multiplication is open-coded
  1101. if the machine supports fullword-to-doubleword a widening multiply
  1102. instruction.  Division and shifts are open-coded only on machines that
  1103. provide special support.  The operations that are not open-coded use
  1104. special library routines that come with GNU CC.
  1105.  
  1106.    There may be pitfalls when you use `long long' types for function
  1107. arguments, unless you declare function prototypes.  If a function
  1108. expects type `int' for its argument, and you pass a value of type `long
  1109. long int', confusion will result because the caller and the subroutine
  1110. will disagree about the number of bytes for the argument.  Likewise, if
  1111. the function expects `long long int' and you pass `int'.  The best way
  1112. to avoid such problems is to use prototypes.
  1113.  
  1114. File: gcc.info,  Node: Zero Length,  Next: Variable Length,  Prev: Long Long,  Up: C Extensions
  1115.  
  1116. Arrays of Length Zero
  1117. =====================
  1118.  
  1119.    Zero-length arrays are allowed in GNU C.  They are very useful as
  1120. the last element of a structure which is really a header for a
  1121. variable-length object:
  1122.  
  1123.      struct line {
  1124.        int length;
  1125.        char contents[0];
  1126.      };
  1127.      
  1128.      {
  1129.        struct line *thisline = (struct line *)
  1130.          malloc (sizeof (struct line) + this_length);
  1131.        thisline->length = this_length;
  1132.      }
  1133.  
  1134.    In standard C, you would have to give `contents' a length of 1, which
  1135. means either you waste space or complicate the argument to `malloc'.
  1136.  
  1137. File: gcc.info,  Node: Variable Length,  Next: Macro Varargs,  Prev: Zero Length,  Up: C Extensions
  1138.  
  1139. Arrays of Variable Length
  1140. =========================
  1141.  
  1142.    Variable-length automatic arrays are allowed in GNU C.  These arrays
  1143. are declared like any other automatic arrays, but with a length that is
  1144. not a constant expression.  The storage is allocated at the point of
  1145. declaration and deallocated when the brace-level is exited.  For
  1146. example:
  1147.  
  1148.      FILE *
  1149.      concat_fopen (char *s1, char *s2, char *mode)
  1150.      {
  1151.        char str[strlen (s1) + strlen (s2) + 1];
  1152.        strcpy (str, s1);
  1153.        strcat (str, s2);
  1154.        return fopen (str, mode);
  1155.      }
  1156.  
  1157.    Jumping or breaking out of the scope of the array name deallocates
  1158. the storage.  Jumping into the scope is not allowed; you get an error
  1159. message for it.
  1160.  
  1161.    You can use the function `alloca' to get an effect much like
  1162. variable-length arrays.  The function `alloca' is available in many
  1163. other C implementations (but not in all).  On the other hand,
  1164. variable-length arrays are more elegant.
  1165.  
  1166.    There are other differences between these two methods.  Space
  1167. allocated with `alloca' exists until the containing *function* returns.
  1168. The space for a variable-length array is deallocated as soon as the
  1169. array name's scope ends.  (If you use both variable-length arrays and
  1170. `alloca' in the same function, deallocation of a variable-length array
  1171. will also deallocate anything more recently allocated with `alloca'.)
  1172.  
  1173.    You can also use variable-length arrays as arguments to functions:
  1174.  
  1175.      struct entry
  1176.      tester (int len, char data[len][len])
  1177.      {
  1178.        ...
  1179.      }
  1180.  
  1181.    The length of an array is computed once when the storage is allocated
  1182. and is remembered for the scope of the array in case you access it with
  1183. `sizeof'.
  1184.  
  1185.    If you want to pass the array first and the length afterward, you can
  1186. use a forward declaration in the parameter list--another GNU extension.
  1187.  
  1188.      struct entry
  1189.      tester (int len; char data[len][len], int len)
  1190.      {
  1191.        ...
  1192.      }
  1193.  
  1194.    The `int len' before the semicolon is a "parameter forward
  1195. declaration", and it serves the purpose of making the name `len' known
  1196. when the declaration of `data' is parsed.
  1197.  
  1198.    You can write any number of such parameter forward declarations in
  1199. the parameter list.  They can be separated by commas or semicolons, but
  1200. the last one must end with a semicolon, which is followed by the "real"
  1201. parameter declarations.  Each forward declaration must match a "real"
  1202. declaration in parameter name and data type.
  1203.  
  1204. ə